package com.huike.web.controller.clues;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.service.ITbCourseService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EthanRuins
 * @date 2023/7/13
 * @apiNote
 */
@RestController
@RequestMapping("/clues/course")
@Api(tags = "课程管理模块")
@AllArgsConstructor
public class TbCourseController extends BaseController {
    private final ITbCourseService courseService;

    @PreAuthorize("@ss.hasPermi('clues:course:insert')")
    @PostMapping
    @ApiOperation(value = "新增课程")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    public AjaxResult<String> insert(@RequestBody TbCourse course) {
        return toAjax(courseService.insert(course));
    }

    @PreAuthorize("@ss.hasPermi('clues:course:update')")
    @PutMapping
    @ApiOperation(value = "修改课程")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    public AjaxResult<String> update(@RequestBody TbCourse course) {
        return toAjax(courseService.update(course));
    }

    @PreAuthorize("@ss.hasPermi('clues:coure:delete')")
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除课程")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
    public AjaxResult<String> deleteByIds(@PathVariable Long[] ids) {
        return toAjax(courseService.deleteByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('clues:course:query')")
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取课程信息")
    public AjaxResult<TbCourse> getById(@PathVariable Long id) {
        return AjaxResult.success(courseService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('clues:course:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取课程列表")
    public TableDataInfo<List<TbCourse>> getList(TbCourse course) {
        startPage();
        List<TbCourse> list = courseService.getList(course);
        return getDataTable(list);
    }

    @GetMapping("/listselect")
    @ApiOperation(value = "获取课程下拉列表")
    public AjaxResult<List<TbCourse>> listSelect(String subject) {
        TbCourse query = new TbCourse();
        if (subject != null) {
            query.setSubject(subject);
        }
        return AjaxResult.success(courseService.getList(query));
    }
}
